package com.lin.controller;

import com.lin.common.error.CustomRuntimeException;
import com.lin.common.rest.ResMsg;
import com.lin.controller.req.AddTranslateSetupReqMsg;
import com.lin.po.TranslateSetup;
import com.lin.service.translatesetup.TranslateSetupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@Api(tags = "设置语言入口")
@RestController
@RequestMapping("/msvc")
public class TranslateSetupController {
    Logger log = LoggerFactory.getLogger(TranslateSetupController.class);

    @Autowired
    private TranslateSetupService translateSetupService;

    @ApiOperation("测试获取设置的列表")
    @PostMapping("/translatesetups")
    public ResMsg<List<TranslateSetup>> translateSetups() throws CustomRuntimeException {
        ResMsg<List<TranslateSetup>> urs = new ResMsg<>();
        List<TranslateSetup> list = translateSetupService.translateSetups(2l);
        return urs.withData(list);
    }

    @ApiOperation("设置好友的通讯语言")
    @PostMapping("/translatesetup")
    public ResMsg<Integer> translateSetup(@Valid @RequestBody AddTranslateSetupReqMsg reqMsg) throws CustomRuntimeException {
        ResMsg<Integer> urs = new ResMsg<>();
        Integer i = translateSetupService.save(reqMsg);
        return urs.withData(i);
    }

    @ApiOperation("删除好友的通讯语言")
    @PostMapping("/deltranslatesetup/{customerId}/{customerRelId}")
    public ResMsg<Integer> delTranslateSetup(@PathVariable Long customerId, @PathVariable Long customerRelId) throws CustomRuntimeException {
        ResMsg<Integer> urs = new ResMsg<>();
        Integer i = translateSetupService.del(customerId, customerRelId);
        return urs.withData(i);
    }
}
